package com.yunkeji.common.enums.app;

import com.yunkeji.common.exception.AppServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 结算类型
 *
 * @author yunkeji
 */
@Getter
@AllArgsConstructor
public enum SettleTypeEnums {
    支付宝("alipay", 1),
    银行卡("bankcard", 2),
    微信("wechatpay", 3);
    private final String code;
    private final Integer type;

    public static SettleTypeEnums getByType(Integer type) {
        SettleTypeEnums[] values = SettleTypeEnums.values();
        Optional<SettleTypeEnums> first =
                Arrays.stream(values).filter(item -> item.getType().equals(type)).findFirst();
        if (first.isPresent()) {
            return first.get();
        } else {
            throw AppServiceException.paramException("结算类型参数异常");
        }
    }

    public static SettleTypeEnums getByCode(String code) {
        SettleTypeEnums[] values = SettleTypeEnums.values();
        Optional<SettleTypeEnums> first =
                Arrays.stream(values).filter(item -> item.getCode().equals(code)).findFirst();
        if (first.isPresent()) {
            return first.get();
        } else {
            throw AppServiceException.paramException("结算类型参数异常");
        }
    }
}
